package com.jr.controller;

import com.jr.pojo.Emp;
import com.jr.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

@Controller
@RequestMapping("emp/")
public class EmpController {
    @Autowired
    private EmpService empService;

    @RequestMapping("login")
    public ModelAndView login(Emp emp){
        ModelAndView mv = new ModelAndView();
        Emp returnemp = empService.queryEmp(emp);
        if (returnemp==null){
            System.out.println("登录失败");
            mv.addObject("mes","登录失败");
            mv.setViewName("/index.jsp");
        }else{
            System.out.println("登录成功");
            ArrayList<Emp> list = empService.queryEmps(new Emp());
            mv.addObject("list",list);
            mv.setViewName("/show.jsp");
        }
        return mv;
    }

}
